package com.access.boot.apisdk.util;

import java.lang.reflect.Method;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author Yangzhen
 * @date 2023/1/11 14:06
 * @since 1.0.0
 */
public class HandlerMethodUtils {

    private static final Map<Class, Object> CACHED_CLASS = new ConcurrentHashMap<>();

    private static final Map<Method, HandlerMethod> METHOD_PARAMETER = new ConcurrentHashMap<>();

    public static void methodAnalysis(Class clazz) {
        synchronized (CACHED_CLASS) {
            if (!CACHED_CLASS.containsKey(clazz)) {
                Method[] declaredMethods = clazz.getDeclaredMethods();
                for (Method method : declaredMethods) {
                    HandlerMethod handlerMethod = new HandlerMethod(clazz, method);
                    METHOD_PARAMETER.put(method, handlerMethod);
                }
            }
        }
    }

    public static HandlerMethod getHandlerMethod(Method method) {
        return METHOD_PARAMETER.get(method);
    }
}
